<?php 

function smarty_function_url($params, &$smarty = null) 
{
	global $conf;
	
	$base = $conf['protocol'] . '://' . $_SERVER['HTTP_HOST'] . str_replace(strchr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']);
	
	$url = $base;
	
	$remove = array();
	if(isset($params['remove']))
	{
		$remove = explode(',',$params['remove']);
	}
	
	$add = array();
	if(isset($params['add']))
	{
		$add = explode(',',$params['add']);
		//get keys and values
		$addParts = array();
		foreach($add  as $v)
		{
			$part = explode('=',$v);
			if(isset($part[0]))
			{
				$addParts[$part[0]] = '';
			}
			if(isset($part[1]))
			{
				$addParts[$part[0]] = $part[1];
			}
		}
	}

	$get = array();
	foreach($_GET as $key => $value)
	{
		if(!in_array($key, $remove))
		{
			$get[$key] = $key.'='.$value;
		}
	}
	
	//add 
	if(isset($addParts))
	{
		foreach($addParts as $key=>$value)
		{
			$get[$key] = $key . '='. $value;
		}
	}
	
	if(!empty($get))
	{
		$getString = '?' . implode('&amp;', $get);
		$url = $base . $getString;
	}
	
	return $url;
	
}


?>
